package com.wanmait.hotelManagement.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.hotelManagement.dao.ActivityDao;
import com.wanmait.hotelManagement.dao.HistoryDao;
import com.wanmait.hotelManagement.dao.MessageDao;
import com.wanmait.hotelManagement.dao.RoomTypeDao;
import com.wanmait.hotelManagement.vo.Activity;
import com.wanmait.hotelManagement.vo.HotelHistory;
import com.wanmait.hotelManagement.vo.Passenger;
import com.wanmait.hotelManagement.vo.RoomType;

/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IndexServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String action = request.getParameter("action");
		if(action==null)
		{
			this.init(request, response);
		}
	}
	
	protected void init(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<Activity> allActivity = ActivityDao.getActivityDao().getActivity();
		request.setAttribute("allActivity", allActivity);
		List<HotelHistory> history = HistoryDao.historyDao().getHistory();
		request.setAttribute("history", history);
		List<RoomType> fiveRooms = (List<RoomType>)RoomTypeDao.getDao().getFiveRoomType();
		request.setAttribute("fiveRooms", fiveRooms);
		
		ArrayList<Passenger> allPassengerMessage = MessageDao.getDao().getAllPassengerMessage();
		request.setAttribute("allPassengerMessage", allPassengerMessage);
		request.getRequestDispatcher("/hotel/index/index.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
